/**
 * ===========================
 * 请求接口
 * ===========================
 */
import { APP_ID } from '../config.js';
import request from "../utils/request.js";

/**
 * 初始化用户
 */
const initUserData = function(data = {}, opt = {}) {
  // return request.post('/initLogin', data, opt);
  return request.post('/initUser', data, opt);
}

/**
 * 登录
 */
const userLogin = function(data, opt = {}) {
  return request.post('/login', data, opt);
}

/**
 * 首页短剧列表
 */
const getPlayletList = function(data, opt = {}) {
  return request.post('/playletList', data, opt);
}

/**
 * 获取短剧剧集列表
 */
const getChapterList = function(data, opt = {}) {
  return request.post('/chapterList', data, opt);
}

/**
 * 添加-追剧/看过
 */
const addCollect = function(data, opt = {}) {
  return request.post('/addCollect', data, opt);
}

/**
 * 取消-追剧/看过
 */
const delCollect = function(data, opt = {}) {
  return request.post('/delCollect', data, opt);
}

/**
 *获取列表-追剧/看过
 */
 const getCollectList = function(data, opt = {}) {
  return request.post('/getCollectList', data, opt);
}

/**
 * 获取文章详情
 */
const getNewsDetail = function(data, opt = {}) {
  return request.post('/newsDetail', data, opt);
}

/**
 * 获取广告配置
 */
const getAdvertConfig = function(slot = 1, opt = {}) {
  let slotId = 0;
  if (slot === 1) {
    slotId = getApp()?.globalData?.AdSlotId || '';
  }
  if (slot === 2) {
    slotId = getApp()?.globalData?.AdGapId || '';
  }
  return request.post('/advert', {brand: getApp()?.globalData.AdBrand || '', slot_id: slotId}, opt);
}

/**
 * 获取渠道配置
 */
const getOaMarkConfig = function(oamark, opt = {}) {
  return request.post('/getOaMarkInfo', {oamark: oamark}, opt);
}

/**
 * 应用行为日志
 */
const sendAppLogs = function(data, opt = {}) {
  return request.post('/writeLog', data, opt);
}

/**
 * 应用行为日志(go)
 */
const sendGoAppLogs = function(data, opt = {}) {
  return request.post('/newWriteLog', data, opt);
}

/**
 * 投放数据上报
 */
const sendReportData = function(data, opt = {}) {
  return request.post('/report', data, opt);
}

/**
 * 看广告解锁记录
 */
const advertUnlockPlaylet = function(data, opt = {}) {
  return request.post('/advertUnlockPlaylet', data, opt);
}

/**
 * 获取充值模版
 */
const getRechargeList = function(data = {}, opt = {}) {
  return request.post('/getRechargeList', data, opt);
}

/**
 * 金币扣减解锁
 */
const coinUnlockPlaylet = function(data, opt = {}) {
  return request.post('/coinUnlockPlaylet', data, opt);
}

/**
 * 抖音下单
 */
const createOrder = function(data, opt = {}) {
  return request.post('/createOrder', data, opt);
}

/**
 * 微信下单
 */
const createWxOrder = function(data, opt = {}) {
  return request.post('/createWxOrder', data, opt);
}

/**
 * 查询订单
 */
const queryOrder = function(data, opt = {}) {
  return request.post('/queryOrder', data, opt);
}

/**
 * 查询微信订单
 */
const queryWxOrder = function(data, opt = {}) {
  return request.post('/queryWxOrder', data, opt);
}

/**
 * 获取消费记录
 */
const getConsumeList = function(data, opt = {}) {
  return request.post('/getConsumeList', data, opt);
}

/**
 * 获取充值记录
 */
const getRechargeLogList = function(data, opt = {}) {
  return request.post('/getRechargeLogList', data, opt);
}

/**
 * 获取用户信息
 */
const getUserInfo = function(data = {}, opt = {}) {
  return request.post('/userInfo', data, opt);
}

/**
 * 获取广告挽留配置
 */
const getRetainConfig = function(data = {}, opt = {}) {
  return request.post('/getRetainConfig', data, opt);
}

/**
 * 获取并记录广告挽留次数
 */
const getRetainNum = function(data = {}, opt = {}) {
  return request.post('/getRetainNum', data, opt);
}

module.exports = {
  initUserData,
  userLogin,
  getPlayletList,
  getChapterList,
  addCollect,
  delCollect,
  getCollectList,
  getNewsDetail,
  getAdvertConfig,
  getOaMarkConfig,
  sendAppLogs,
  sendGoAppLogs,
  sendReportData,
  advertUnlockPlaylet,
  getRechargeList,
  coinUnlockPlaylet,
  createOrder,
  createWxOrder,
  queryOrder,
  queryWxOrder,
  getConsumeList,
  getRechargeLogList,
  getUserInfo,
  getRetainConfig,
  getRetainNum
};